home *** CD-ROM | disk | FTP | other *** search
/ Exame Informatica 139 / Exame Informatica 139.iso / Revista / Flash / Uniform Server / diskw / docs / SRC / uniserv.c < prev   
Encoding:
C/C++ Source or Header  |  2005-02-22  |  1.5 KB  |  44 lines

  1. // Copyright 2004 - 2005 The Uniform Server Development Team
  2. // Runs a hidden process. Waits till it ends then next one. [windows application]
  3. // Compile with lcc-win32
  4. // version 1.1
  5.  
  6. #include <windows.h>
  7. #include <stdio.h>
  8.  
  9. int main( int argc, char *argv[] )
  10. {
  11.   STARTUPINFO si;
  12.   PROCESS_INFORMATION pi;
  13.  
  14.   if (argc>1) {
  15.     memset(&si, 0, sizeof(si));
  16. //    ZeroMemory( &si, sizeof(si) );
  17.     si.cb = sizeof(si);
  18.     si.wShowWindow = SW_HIDE;
  19.     si.dwFlags = STARTF_USESHOWWINDOW;
  20.     ZeroMemory( &pi, sizeof(pi) );
  21.  
  22.     // Start the child process.
  23.     CreateProcess( NULL,   // No module name (use command line).
  24.         TEXT(argv[1]), // Command line.
  25.         NULL,             // Process handle not inheritable.
  26.         NULL,             // Thread handle not inheritable.
  27.         FALSE,            // Set handle inheritance to FALSE.
  28.         0,                // No creation flags.
  29.         NULL,             // Use parent's environment block.
  30.         NULL,             // Use parent's starting directory.
  31.         &si,              // Pointer to STARTUPINFO structure.
  32.         &pi );             // Pointer to PROCESS_INFORMATION structure.
  33.     // Wait until child process exits.
  34.     if (argc>2) {
  35.       WaitForSingleObject( pi.hProcess, INFINITE );
  36.       CreateProcess( NULL, TEXT(argv[2]), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi );
  37.     }
  38.     // Close process and thread handles.
  39.     CloseHandle( pi.hProcess );
  40.     CloseHandle( pi.hThread );
  41.   }
  42.   return 0;
  43. }
  44.